package com.zhongyouyun.jyj.service.imp;

import com.zhongyouyun.jyj.model.ReportModel;
import com.zhongyouyun.jyj.mapper.ReportMapper;
import com.zhongyouyun.jyj.model.ReportZbModel;
import com.zhongyouyun.jyj.pojo.ReportPojo;
import com.zhongyouyun.jyj.service.ReportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongyouyun.jyj.service.ReportZbService;
import com.zhongyouyun.utils.ModelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * @Author: shenyi
 * @Date: 2023-11-17
 * @Description: 教育局举报内容服务实现类
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ReportServiceImpl extends ServiceImpl<ReportMapper, ReportModel> implements ReportService {

    @Autowired
    private ReportZbService reportZbService;
    /*
     * @Author: shenyi
     * @Date: 2021-09-08
     * @Description: 分页查询
     * @param page 分页数据  lambdaQueryWrapper where 条件 和排序
     */
    @Override
    public IPage<ReportModel> selectPage(Page<ReportModel> page, QueryWrapper<ReportModel> queryWrapper) {
        return this.baseMapper.selectPage(page, queryWrapper);
    }


    /*
     * @Author: shenyi
     * @Date: 2021-09-08
     * @Description: 查询全部
     * @param   lambdaQueryWrapper where 条件 和排序
     */
    @Override
    public List<ReportModel> selectList(QueryWrapper<ReportModel> queryWrapper) {
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public IPage<ReportPojo> selectPojoPage(Page page, QueryWrapper queryWrapper) {
        return this.baseMapper.selectPojoPage(page, queryWrapper);
    }

    @Override
    public boolean saveOrUpdate(ReportModel reportModel, List<String> urls) {
        try {
            ModelUtils modelutils = new ModelUtils();
            modelutils.initModel(reportModel, "510");
            reportModel.setDeptId(1L);
            this.saveOrUpdate(reportModel);
            for (String url:urls) {
                ReportZbModel reportZbModel = new ReportZbModel();
                reportZbModel.setUrl(url);
                reportZbModel.setReportId(reportModel.getId());
                ModelUtils modelutils1 = new ModelUtils();
                modelutils1.initModel(reportZbModel, "510");
                reportZbModel.setDeptId(1L);
                reportZbService.saveOrUpdate(reportZbModel);
            }
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
